package com.srwl.mytx.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RemoteViews;
import android.widget.TextView;

import com.srwl.mytx.R;
import com.srwl.mytx.domain.Orders;
import com.srwl.mytx.domain.User;
import com.srwl.mytx.utils.GlideLoadUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wei on 2016/6/7.
 */
@RemoteViews.RemoteView
public class LiveOfferView extends RelativeLayout {
    @BindView(R.id.avatar)
    ImageView avatar;
    @BindView(R.id.tv_nick)
    TextView name;
    @BindView(R.id.tv_offer)
    TextView tv_amount;
    @BindView(R.id.tv_max_offer)
    TextView tv_maxOffer;
    private Orders orders;
    private  Context context;

    public LiveOfferView(Context context) {
        super(context);
        this.context=context;
        init(context, null);
    }

    public LiveOfferView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        init(context, attrs);

    }

    public LiveOfferView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
        this.context=context;
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.widget_live_offer, this);
        ButterKnife.bind(this);
    }

    public void setupView(Orders orders) {
        User user = orders.getUser();
        tv_amount.setText(orders.getAmount() + "");
        if (user != null) {
            name.setText(user.getUsername());
            //Glide.with(getContext()).load(user.getAvatar()).error(R.drawable.tx_default_avatar).into(this.avatar);
            GlideLoadUtils.glideLoad(context, user.getAvatar(), avatar, R.drawable.tx_default_avatar_1);
        }
    }


    public void setMaxOffer(String maxoffer) {
        this.tv_maxOffer.setText(maxoffer);
    }

    public View getAmountTextView() {
        return tv_amount;
    }
}
